home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / hd-install / thor.lha / rexx / BBSRead / DelDupes.br < prev    next >
Text File  |  1996-10-18  |  4KB  |  141 lines

  1. /*
  2. ** $VER: DelDupes.br 1.3 (18.10.96)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. ** This script will delete duplicate entries in the file database. The first
  6. ** occurence of each filename will be kept, subsequent occurences IN ANY FILE
  7. ** AREA will be deleted. (currently, I'll do something about this later)
  8. **
  9. **
  10. ** Usage:   DelDupes.br SYSTEM/M,ALL/S,PURGE/S,QUIET/S
  11. **
  12. ** Args:    SYSTEM      The name of the system you want to check. Multiple
  13. **                      systems can be specified
  14. **          ALL         Check dupes on all systems
  15. **          PURGE       Perform file database maintainance afterwards
  16. **          QUIET       Don't display any progress information
  17. **
  18. ** Example: DelDupes.br "Ygdrasil" "Ultima Thule" PURGE
  19. **
  20. **
  21. ** Ideas:   GUI interface if run from Thor
  22. **          Support SortMail's exclude file
  23. **          Allow identical filenames across file areas
  24. **
  25. */
  26.  
  27. options results
  28.  
  29. signal on break_c
  30. signal on halt
  31.  
  32. trace off
  33.  
  34. parse arg arguments
  35.  
  36. /* Find BBSREAD ARexx ports' */
  37.  
  38. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  39.  
  40. /* Parse command line arguments */
  41.  
  42. template = 'SYSTEM/M,PURGE/S,QUIET/S,ALL/S'
  43. args.ALL = 0; args.PURGE = 0; args.QUIET = 0
  44.  
  45. if arguments = '' then do
  46.     say 'Template: 'template
  47.     exit(0)
  48.     end
  49.  
  50. address(bbsread)
  51. 'READARGS 'template' 'args' CMDLINE 'arguments
  52. if rc ~= 0 then do
  53.     say BBSREAD.LASTERROR
  54.     say 'Template: 'template
  55.     exit(0)
  56.     end
  57.  
  58. if (symbol('args.SYSTEM.COUNT') = 'VAR') & (args.ALL) then do
  59.     say 'You must specify either one or more system names or ALL.'
  60.     say 'Template: 'template
  61.     exit(0)
  62.     end
  63.  
  64. if args.ALL then GETBBSLIST args.SYSTEM
  65.  
  66. FDF_DELETED = '00000001'x
  67.  
  68. totchecked = 0; dupes = 0; 
  69.  
  70. do h = 1 to args.SYSTEM.COUNT
  71.  
  72.     /* Initialize variables */
  73.  
  74.     checked = 0; dupeshere = 0
  75.  
  76.     /* Start the work... */
  77.  
  78.     'GETFAREALIST BBSNAME "'args.SYSTEM.h'" STEM 'fareas
  79.     if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  80.  
  81.     if fareas.COUNT = 0 then do
  82.         say 'No file areas on this system.'
  83.         exit(0)
  84.         end
  85.  
  86.     if ~args.QUIET then say '1B'x'[4mChecking for dupes on "'args.SYSTEM.h'" - 'fareas.COUNT' file areas.' || '1B'x'[0m' || '1B'x'[1B'
  87.  
  88.     do i = 1 to fareas.COUNT
  89.         drop fadata.
  90.         'GETFAREADATA BBSNAME "'args.SYSTEM.h'" FAREANAME "'fareas.i'" STEM 'fadata
  91.         if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  92.  
  93.         if ~args.QUIET then do
  94.             say '1B'x'[1A' || '1B'x'[K' || '1B'x'[1m'fareas.i || '1B'x'[0m'
  95.             say '1B'x'[1A' || '1B'x'[20Ccontains 'fadata.NUMFILES' files.'
  96.             say '1B'x'[1A' || '1B'x'[42C' || '1B'x'[3mProcessing...' || '1B'x'[0m' || '1B'x'[1B'
  97.             end
  98.  
  99.         thisfile = fadata.FIRSTFILE
  100.  
  101.         if fadata.NUMFILES > 0 then do until checked = fadata.NUMFILES
  102.             drop filetags. filedata. found.
  103.             'READBRFILE BBSNAME "'args.SYSTEM.h'" FAREANAME "'fareas.i'" FILENR 'thisfile' TAGSSTEM 'filetags' DATASTEM 'filedata
  104.             if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  105.             nextfile = result
  106.  
  107.             if (bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED) then do
  108.                 'SEARCHBRFILE BBSNAME "'args.SYSTEM.h'" STEM 'found' SEARCH "'filetags.NAME'" NAME'
  109.                 if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  110.  
  111.                 do j = 1 to found.FILEAREA.COUNT
  112.                     do k = 1 to found.FILE.j.COUNT
  113.                         if found.FILE.j.k ~= thisfile then do
  114.                             if ~args.QUIET then say '1B'x'[1A' || '1B'x'[KDupe: 'found.FILEAREA.j'/'filetags.NAME
  115.                             'WRITEBRFILE BBSNAME "'args.SYSTEM.h'" FAREANAME "'found.FILEAREA.j'" UPDATEFILENR 'found.FILE.j.k' DELETEFILE'
  116.                             if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  117.  
  118.                             if ~args.QUIET then say '1B'x'[1A' || '1B'x'[42CDELETED'
  119.                             dupes = dupes + 1; dupeshere = dupeshere + 1
  120.                             end
  121.                         end
  122.                     end
  123.  
  124.                 checked = checked + 1; totchecked = totchecked + 1
  125.                 thisfile = nextfile
  126.                 end
  127.             end
  128.  
  129.         if ~args.QUIET then say '1B'x'[2A' || '1B'x'[42C' || '1B'x'[K'dupeshere' dupes found.' || '1B'x'[1B'
  130.         checked = 0; dupeshere = 0
  131.         end
  132.  
  133.         if args.PURGE & ~args.QUIET then 'PACKDATAFILE "'args.SYSTEM.h'" FILEDATA SHOWPROGRESS'
  134.         if args.PURGE & args.QUIET then 'PACKDATAFILE "'args.SYSTEM.h'" FILEDATA'
  135.         if rc ~= 0 then do; say BBSREAD.LASTERROR; exit(0); end
  136.     end
  137.  
  138. break_c:
  139. halt:
  140. if ~args.QUIET then say 'Checked 'totchecked' files and found 'dupes' duplicates.'
  141.